package com.thiny.android.game.thunderbolt.role;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import com.thiny.android.game.thunderbolt.view.GameView;
/**
 * 爆炸类
 * 
 * @author THINY
 *
 */
public class Explode {

	/**
	 * 爆炸中心的x,y坐标
	 */
	private float x;
	private float y;

	private int bitmapWidth, bitmapHeight;
	
	// 所有爆炸的帧数组
	private Bitmap[] bitmaps;
	// 当前帧计数
	private int i = 0;	
	// 当前帧
	private Bitmap bitmap;

	public Explode(GameView gameView, BaseRole baseRole) {
		this.x = baseRole.getX();
		this.y = baseRole.getY();

		if (baseRole instanceof Bullet) {
			bitmaps = gameView.bulletExplodeBmps;
		}else {
			bitmaps = gameView.enemyExplodeBmps;
		}	

		bitmapWidth = bitmaps[0].getWidth();
		bitmapHeight = bitmaps[0].getHeight();
	}

	public void draw(Canvas canvas) {// 绘制方法
		canvas.drawBitmap(bitmap, x - bitmapWidth / 2, y - bitmapHeight / 2,
				null);
	}

	
	//检测是否还存在下一帧
	public boolean nextFrame() {// 换帧，成功返回true。否则返回false
		if (i < bitmaps.length) {
			bitmap = bitmaps[i];
			i++;
			return true;
		}
		return false;
	}
}